﻿<template>
	<el-dialog :title="!dataForm.id ? '新建' : '编辑'" :close-on-click-modal="false" :visible.sync="visible"
		class="SHZY-dialog SHZY-dialog_center" lock-scroll width="600px">
		<el-row :gutter="15" class="">
			<el-form ref="elForm" :model="dataForm" size="small" label-width="110px" label-position="right" :rules="rules">
				<el-col :span="24">
					<el-form-item label="函数描述" prop="describe">
						<el-input v-model='dataForm.describe' placeholder='请输入' clearable required
							:style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="函数所在类库" prop="classLibrary">
						<el-input v-model='dataForm.classLibrary' placeholder='请输入' clearable required
							:style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="函数所在类" prop="className">
						<el-input v-model='dataForm.className' placeholder='请输入' clearable required
							:style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="有效标志" prop="enabledMark">
						<el-switch v-model='dataForm.enabledMark' :active-value='1' :inactive-value='0'>
						</el-switch>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
import { getFunctionInfo, createFunction, updateFunction } from '@/api/system/interface/function'
export default {
	components: {},
	props: [],
	data() {
		return {
			btnLoading: false,
			loading: false,
			visible: false,
			dataForm: {
				id: '',
				describe: undefined,
				classLibrary: undefined,
				className: undefined,
				enabledMark: 1,
			},
			rules: {
				describe: [
					{
						required: true,
						message: '请输入函数描述',
						trigger: '"blur"'
					},
				],
				classLibrary: [
					{
						required: true,
						message: '请输入函数所在类库',
						trigger: '"blur"'
					},
				],
				className: [
					{
						required: true,
						message: '请输入函数所在类',
						trigger: '"blur"'
					},
				],
			},
		}
	},
	computed: {},
	watch: {},
	created() {
	},
	mounted() {
	},
	methods: {
		goBack() {
			this.$emit('refresh')
		},
		init(id) {
			this.dataForm.id = id || 0;
			this.visible = true;
			this.$nextTick(() => {
				this.$refs['elForm'].resetFields();
				if (this.dataForm.id) {
					getFunctionInfo(this.dataForm.id).then(res => {
						this.dataForm = res.data;
					})
				}
			});
		},
		dataFormSubmit() {
			this.$refs['elForm'].validate((valid) => {
				if (valid) {
					this.btnLoading = true;
					const formMethod = !this.dataForm.id ? createFunction : updateFunction;

					formMethod(this.dataForm).then((res) => {
						this.btnLoading = false;
						this.$message({
							message: res.msg,
							type: 'success',
							duration: 1000,
							onClose: () => {
								this.visible = false,
									this.$emit('refresh', true)
							}
						})
					}).catch((res) => {
						this.btnLoading = false;
					})
				}
			})
		},
	}
}
</script>
